package net.crowdloud.server.DatabaseAccess.solution;

import javax.jdo.PersistenceManager;

import net.crowdloud.server.DatabaseAccess.user.GetUser;
import net.crowdloud.server.DatabaseAccess.user.User;

public class SaveSolution {

	public static void addNew(PersistenceManager persistenceManager,
			Long userID, net.crowdloud.shared.entities.Solution solution, String tags) {

		User userDatabase = GetUser.getUserDatabase(persistenceManager, userID);

		userDatabase.getUserSolutions().add(
				ConvertSolutionToDatabase.getDatabaseSolution(new Solution(),
						solution, tags));

		persistenceManager.makePersistent(userDatabase);
	}

	public static void update(PersistenceManager persistenceManager,
			net.crowdloud.shared.entities.Solution solution, String tags) {

		Solution solutionDatabase = GetSolution.getSolutionDatabase(
				persistenceManager, solution.getSolutionID());

		ConvertSolutionToDatabase.getDatabaseSolution(solutionDatabase,
				solution, tags);

		persistenceManager.makePersistent(solutionDatabase);
	}
}
